package br.edu.univas.si.es.correios.model;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

	private static final SessionFactory sessionFactory;

	static {
		try {
	           AnnotationConfiguration config = new AnnotationConfiguration();
	            config.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
	            config.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
	            config.setProperty("hibernate.connection.url", "jdbc:postgresql://localhost:5432/correio");
	            config.setProperty("hibernate.connection.username", "postgres");
	            config.setProperty("hibernate.connection.password", "123456");
	            config.setProperty("hibernate.show_sql", "true");
	            config.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
	            config.setProperty("hibernate.current_session_context_class", "thread");
	            config.setProperty("hibernate.hbm2ddl.auto", "update");
	 
	            // Add your mapped classes here:
	            config.addAnnotatedClass(Order.class);
	 
	            sessionFactory = config.buildSessionFactory();
	            

		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}
